package com.yinghuo.risk.frigate.generator

/**
 * com.yinghuo.risk.frigate.generator
 *
 * @author 白雨浓
 * date: 2018/10/23 20:50
 * content:
 */
class MakeClass {

    fun getConfig(map: Map<String, Any>): String {


        var out = "\n"

        map.forEach { k, m ->

            val cMap = m as Map<*, *>

            val group = k.replace("-", "_")

            var content = "interface $group {\n"

            cMap.forEach { permission, msg ->
                content += this.handle(k, permission as String, msg as String)
            }

            content += "}\n\n"
            out += content
        }
        return out
    }

    private fun handle(group: String, permission: String, msg: String): String {
        var out = "\n"

        out += "/*$msg*/\n"
        out += "String ${permission.toUpperCase().replace("#", "_")} = \"$group:$permission\";\n"


        return out
    }

}